package main

import (
	"fmt"
	"math/rand"
	"sort"
	"time"
)

func test1() {
	fmt.Println("1.请问s1、s2内各有什么元素？")
	fmt.Println("1.s1为[0,0,0],s2为[0,0,0,1]")
	fmt.Println("2.s1修改一个元素会影响s2吗？s2修改一个元素会影响s1吗？")
	fmt.Println("2.因为s1与s2使用的相同的底层数组,所以更改s1同样也会更改s2的值.修改s2的前三位同样会更改s1的值")
	fmt.Println("3.s2再增加一个元素会怎么样？")
	fmt.Println("s2增加一个元素后容量不够,会将原来的数值重新复制到新的底层数组中,后续更改s2的值不会影响s1")
}
func test2() {
	a := [...]int{1, 4, 9, 16, 2, 5, 10, 15}
	a1 := make([]int, len(a)-1)
	for i := 0; i < len(a)-1; i++ {
		a1[i] = a[i] + a[i+1]
	}
	fmt.Println("数组值为:", a)
	fmt.Println("切片值为:", a1)
}
func test3() {
	src := rand.NewSource(time.Now().UnixNano())
	gen := rand.New(src)
	a := make([]int, 100)
	for i := 0; i < 100; i++ {
		a[i] = gen.Intn(401) - 200
	}
	sort.Ints(a)
	prev := a[0]
	count := 1
	for i := 0; i < 100; i++ {
		if prev == a[i] {
			count++
		} else {
			prev = a[i]
			count = 1
		}
		fmt.Printf("%d \t重复次数：%d\n", prev, count)
	}
}
func main() {
	test1()
	test2()
	test3()
}
